#!/usr/bin/python

from Queue import Queue
import random 
import threading
import time

class Products:
    
    def __init__(self,cou,dis):
        self.count = cou
        self.discrible = dis
    def get(self):
        a= [self.count , self.discrible]
        return a

class Producer(threading.Thread):
    def __init__(self,name,queue):
        threading.Thread.__init__(self,name = name)
        self.data = queue
    def run (self):
        for i in range(5):
            print "%s %s is producing %d to the queue!/n"%(time.ctime(), self.getName(),i)
            some = "aaaa"
            other = Products(i,"test")
            #self.data.put(str(i)+ some)
            self.data.put(other)
            time.sleep(random.randrange(5))
        print '%s %s finied!' % (time.ctime(),self.getName())

class Consumer(threading.Thread):
    def __init__(self,name,queue):
        threading.Thread.__init__(self,name = name)
        self.data = queue
    def run(self):
        for i in range(5):
            val = self.data.get()
            val = val.get()
            print "%s: %s is consuming . %s %s in the queue is consumed!/n"%(time.ctime(),self.getName(),val[0],val[1])
            time.sleep(random.randrange(5))
        print "%s : %s finished !" %(time.ctime(), self.getName())
        
def main():
    queue= Queue()
    producer = Producer('pro',queue)
    consumer = Consumer('con',queue)
    producer.start()
    consumer.start()
    producer.join()
    consumer.join()
    print 'All threads terminate !'

if __name__=="__main__":
    main()
